<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>后台管理系统</title>
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport"
	content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="format-detection" content="telephone=no">
<link rel="stylesheet" href="./css/x-admin.css" media="all">

</head>
<body>
	<div class="x-nav">
		<span class="layui-breadcrumb"> <a><cite>首页</cite></a> <a><cite>信息管理</cite></a>
			<a><cite>教员列表</cite></a>
		</span> <a class="layui-btn layui-btn-small"
			style="line-height: 1.6em; margin-top: 3px; float: right"
			href="javascript:location.replace(location.href);" title="刷新"><i
			class="layui-icon" style="line-height: 30px">ဂ</i></a>
	</div>
	<div class="x-body">
		<xblock>
		<button class="layui-btn layui-btn-danger" onclick="delAll()">
			<i class="layui-icon">&#xe640;</i>批量删除
		</button>
		<button class="layui-btn" onclick="banner_add('添加教员','TeachAdd.jsp','750','750')">
			<i class="layui-icon">&#xe608;</i>添加
		</button>
		<form action="TeachServlet" method="post" style="display: inline-block">
           	<div class="layui-input-inline">
	           	<select class="layui-select" name="selectKey" id="selectKey"></select>
			</div>
			<div class="layui-input-inline">
				<input type="hidden" id="select" value="<%=request.getAttribute("selectKey")%>">
				<input type="text" name="keyword" placeholder="请输入要查询的信息"
					id="keyword" autocomplete="off" class="layui-input"
					value="${keyword}" style="width:300px">
			</div>
			<div class="layui-input-inline" style="width: 50px">
				<button class="layui-btn" type="submit" lay-submit="" lay-filter="sreach">
					<i class="layui-icon">&#xe615;</i>
				</button>
			</div>
		</form>
		<span class="x-right" style="line-height: 40px">共有数据：<span
			class="layui-badge">${pd.totalCount}</span> 条
		</span></xblock>

		<table class="layui-table">
			<thead>
				<tr>
					<th><input type="checkbox" value="" name="all" id="all"></th>
					<th>教员编号</th>
					<th>教员名</th>
					<th>教员性别</th>
					<th>教员学历</th>
					<th>教员电话</th>
					<th>教员简介</th>
					<th>教员照片</th>
					<th>操作</th>
				</tr>
			</thead>
			<tbody id="x-img">
				<c:if test="${pd == null}">
					<c:redirect url="TeachServlet"></c:redirect>
				</c:if>
				<c:if test="${pd != null}">
					<c:forEach items="${pd.data}" var="teach">
						<tr>
							<td><input type="checkbox" value="${teach.teacherNo}" name="one" class="one"></td>
							<td>${teach.teacherNo}</td>
							<td>${teach.teacherName}</td>
							<td>${teach.teacherSex}</td>
							<td>${teach.teacherXl}</td>
							<td>${teach.teacherTel}</td>
							<td>${teach.teacherDesc}</td>
							<td><img src="${teach.teacherPic}" width="45px" height="42px"></td>
							<td class="td-manage"><a title="编辑" href="javascript:;"
								onclick="banner_edit('编辑','TeachEdit.jsp?teacherNo=${teach.teacherNo}&teacherName=${teach.teacherName}&teacherSex=${teach.teacherSex}&teacherXl=${teach.teacherXl}&teacherTel=${teach.teacherTel}&teacherDesc=${teach.teacherDesc}&teacherPic=${teach.teacherPic}','4','750','750')" class="ml-5" style="text-decoration:none">
								<i class="layui-icon">&#xe642;</i>
							</a> <a title="删除" href="javascript:;" onclick="banner_del(this,${teach.teacherNo})"
								style="text-decoration: none"> <i class="layui-icon">&#xe640;</i>
							</a></td>
						</tr>
					</c:forEach>
				</c:if>
			</tbody>
		</table>

		<div id="page" style="text-align: center"></div>
	</div>
	<script src="js/jquery-2.0.3.js" charset="utf-8"></script>
	<script src="layui/layui.js" charset="utf-8"></script>
	<script src="./js/x-layui.js" charset="utf-8"></script>
	<script>
	layui.use(['laypage', 'layer'], function(){
		  var laypage = layui.laypage,
		  layer = layui.layer;
		//完整功能
		//elem [显示位置]  count [总数据数]  curr [当前页码]  
		//limit [当前页码的数据数]  theme [颜色]
		laypage.render({
			elem : 'page',    
			count : ${pd.totalCount},  
			curr: ${pd.page},
			theme: 'lightblue',	
			layout : [ 'prev', 'page', 'next'],
			jump : function(obj,first) { //跳转页面时的动作
				if(!first){
					location.href="TeachServlet?page="+obj.curr+"&keyword="+$("#keyword").val();
				}
			}
		});
	});
	/*添加*/
	function banner_add(title, url, w, h) {
		x_admin_show(title, url, w, h);
	}
	// 编辑
	function banner_edit(title, url, id, w, h) {
		x_admin_show(title, url, w, h);
	}
	/*删除*/
	function banner_del(obj, id) {
		layer.confirm('确认要删除'+id+'吗？', {
			icon : 3,
			title : '提示信息'
		}, function(index) {
			$.ajax({
				type : "post",
				url : "TeachServlet",
				data : {
					teachNo : id,
					op : "del"
				},
				success:function(data){
					if(data.code == 200 ){
						layer.msg(data.msg,{icon:1,time:1000});
	                    setTimeout(function(){
	                    	location.replace(location.href);
	                    },1000);
	                    return false;
					}else{
						layer.msg(data.msg,{icon:5,time:2000});
	                    return false;
					}
			   },
			   dataType:"json"
		  });
			return false;
		});
	}
	/*复选框*/
	$(function(){
		$("#all").click(function(){
			$("input[class = one ]").prop("checked",this.checked);
		});
	})
	/* 批量删除提交 */
	function delAll() {
		var result = "";
		$(".one").each(function(){
			if($(this).is(':checked')){
				result += $(this).val()+",";
			}else{}
		})
		layer.confirm('确认要删除吗？', {
			icon: 3,
			title: '提示信息'
		}, function(index) {
			$.ajax({
				type:"post",
				url:"TeachServlet",
				data:{
					r : result,
					op : "delAll"
				},
				success:function(data){
					if(data.code == 200){
						layer.msg(data.msg,{icon:1,time:1000});
	                    setTimeout(function(){
	                    	location.replace(location.href);
	                    },1000);
	                    return false;
					}else{
						layer.msg(data.msg,{icon:5,time:2000});
	                    return false;
					}
				},
				dataType:"json"
			});
		});
	}
	</script>
	
	<script type="text/javascript">
		var selectArr = ["教员名","教员号","性别","学历"];
		var selectKey = $("#select").val();
		console.log(selectKey);
		$(function(){
			if(selectKey != ""){
				$("#selectKey").append("<option value="+selectKey+">"+selectKey+"</option>");
				$.each(selectArr,function(i,o){
					if(o != selectKey){
						$("#selectKey").append("<option value="+o+">"+o+"</option>");
					}
				})
			}else{
				$.each(selectArr,function(i,o){
					$("#selectKey").append("<option value="+o+">"+o+"</option>");
				})
			}
		})
	</script>

</body>
</html>